package com.example.helloword.jcip.chap6;

import lombok.extern.slf4j.Slf4j;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * SingleThreadWebServer
 * <p/>
 * Sequential web server
 *
 * @author Brian Goetz and Tim Peierls
 */

@Slf4j
public class SingleThreadWebServer {
    public static void main(String[] args) throws IOException {
        ServerSocket socket = new ServerSocket(81);
        while (true) {
            Socket connection = socket.accept();
            handleRequest(connection);
            connection.close();
        }
    }

    private static void handleRequest(Socket s) throws IOException {
        // request-handling logic here
        //休息1s-然后进行返回
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        ;
//        DataInputStream dis=new DataInputStream(s.getInputStream());
//        String  str=(String)dis.readUTF();
//        System.out.println("message= "+str);
        System.out.println("1111");
    }
}
